//
//  ContentView.m
//  规格选择
//
//  Created by 徐宏飞 on 16/5/7.
//  Copyright © 2016年 徐宏飞. All rights reserved.
//

#import "Pick_ContentView.h"
#import "PickContCollectionViewCell.h"

//#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
#define RGBA(R/*红*/, G/*绿*/, B/*蓝*/, A/*透明*/) \
[UIColor colorWithRed:R/255.f green:G/255.f blue:B/255.f alpha:A]

static  NSString *styleCollecitonViewCell_ID = @"PickContCollectionViewCell";



@interface Pick_ContentView ()<UICollectionViewDelegate, UICollectionViewDataSource>

@property (weak, nonatomic) IBOutlet UICollectionView *styleCollecitonView;
@property (weak, nonatomic) IBOutlet UILabel *lblNum;

@end


@implementation Pick_ContentView


-(void)awakeFromNib{
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    
    //item
    CGSize size = CGSizeMake(115, 30);
    
    //4  4s  5  5s
    if (SCREEN_WIDTH == 320) {
        size = CGSizeMake(90, 25);
    }
    
    //6 6s
    if (SCREEN_WIDTH == 375) {
        size = CGSizeMake(105, 30);
    }
    
    
    
    flowLayout.itemSize = size;
    flowLayout.sectionInset = UIEdgeInsetsMake(5, 0, 0, 0);
    flowLayout.minimumLineSpacing = 10;
    flowLayout.minimumInteritemSpacing = 5;
    
    
    _styleCollecitonView.collectionViewLayout = flowLayout;
    
    //注册item
    [_styleCollecitonView registerNib:[UINib nibWithNibName:@"PickContCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:styleCollecitonViewCell_ID];
}

#pragma mark - 行数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 5;
}




#pragma mark - item
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    PickContCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:styleCollecitonViewCell_ID forIndexPath:indexPath];
    
    
    cell.layer.cornerRadius = 4;
    [cell.layer masksToBounds];
    
    cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame];
    cell.selectedBackgroundView.backgroundColor = RGBA(71, 183, 159, 1);
    
    return cell;
}



#pragma mark - 选中执行
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"选中第几个");
}

#pragma mark - 减
- (IBAction)MinusBtnClick:(id)sender {
    NSString *str = self.lblNum.text;
    NSInteger num = str.intValue;
    num --;
    if (num <= 1) {
        num = 1;
    }
    self.lblNum.text = [NSString stringWithFormat:@"%ld", num];
    
    //设置其他属性
    
}

#pragma mark - 加
- (IBAction)addBtnClick:(id)sender {
    NSString *str = self.lblNum.text;
    NSInteger num = str.intValue;
    num ++;

    self.lblNum.text = [NSString stringWithFormat:@"%ld", num];
    
    //设置其他属性
}

#pragma mark - 关闭
- (IBAction)tapCloseAction:(id)sender {
    [self.delegete disMissCurrentPageWithMessage:@"关闭"];
}


#pragma mark - 立即购买
- (IBAction)buyNowAction:(id)sender {
    
  [self.delegete disMissCurrentPageWithMessage:@"立即购买"];
}

@end






